package com.zf.admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zf.admin.pojo.QueryVo;
import com.zf.admin.pojo.Solve;
import com.zf.admin.pojo.Wrong;
import com.zf.admin.pojo.Zulist;
import com.zf.admin.service.PaidService;
import com.zf.admin.service.SolveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/wrong")
public class WrongController {
    @Autowired
    private SolveService solveService;
    @Autowired
    private PaidService paidService;

    //管理员查找所有已处理的报障
    @RequestMapping("/selectall")
    public String selectall(Model model, QueryVo vo, @RequestParam(required = false, defaultValue = "1") Integer page,
                            @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Solve> list = solveService.selectall(vo);
        PageInfo<Solve> p = new PageInfo<Solve>(list);
        Integer count = solveService.selectcount(vo);
        model.addAttribute("solve", list);
        model.addAttribute("count", count);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "solve.jsp");
        model.addAttribute("vo", vo);
        return "admin/main1";
    }

    //管理员删除已处理报障记录
    @RequestMapping("/deletesolve")
    public String deletesolve(Integer id) {
        solveService.deletesolve(id);
        return "redirect:selectall";
    }


    //管理员查看所有未处理报障
    @RequestMapping("/wronglist")
    public String wronglist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page,
                            @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        QueryVo vo = new QueryVo();
        PageHelper.startPage(page, pageSize);
        List<Wrong> list = solveService.findwrong(vo);
        PageInfo<Wrong> p = new PageInfo<Wrong>(list);
        model.addAttribute("wrong", list);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "wrong.jsp");
        return "admin/main1";
    }

    //管理员处理报障
    @RequestMapping("/gotosolve")
    public String gotosolve(Integer id, Model model) {

        Wrong wrong = solveService.findbyid(id);
        Solve solve = new Solve();
        solve.setHouse_id(wrong.getHouse_id());
        solve.setAddress(wrong.getAddress());
        solve.setDate(wrong.getDate());
        solve.setDetail(wrong.getDetail());
        solve.setName(wrong.getName());
        solve.setUserlist_id(wrong.getUserlist_id());
        solve.setStatus("已处理");
        solveService.gotosolve(id, solve);
        model.addAttribute("error", "duesucess");
        return "redirect:selectall";
    }
}
